package com.one.monitoring.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author lxh
 * @description MQ测试
 * @time 2023/11/17 15:47
 **/
@Slf4j
public class MQTestUtils {

    public static Integer testMQ(){
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("16.162.198.48");  // 换成自己的ip
        factory.setPort(5672);  // 一般默认端口为5672
        factory.setUsername("root");
        factory.setPassword("dTi64O28qT");
        try {
            Connection connection = factory.newConnection();
            boolean open = connection.isOpen();
            connection.close();
            if (open){
                log.info("MQ连接成功！");
                return 1;
            }
        } catch (IOException e) {
            log.info("MQ连接异常:{}",e.getMessage());
        } catch (TimeoutException e) {
            log.info("MQ连接异常:{}",e.getMessage());
        }
        return 2;
    }
    public static void main(String[] args) {
        Integer integer = testMQ();
        System.out.println(integer);
    }
}
